<?php

namespace App\Http\Controllers\CmsApi;

use Illuminate\Http\Request;
use App\Lib\Response;
use App\Http\Controllers\BaseController;
use App\Http\Model\Hint;
use App\Http\Services\ShortcutWordServices;

class InnerShortcutWordController extends BaseController
{
    protected $shortcutWordService;

    public function __construct()
    {
        $this->shortcutWordService = new ShortcutWordServices();

    }

    /**
     * 添加快捷语
     */
    public function addShortcutWord(Request $request)
    {
        $param['content'] = $request->input("content");
        $param['data_type'] = $request->input("data_type");
        $param['sort'] = (int) $request->input("sort");
        $param['admin_id'] = $request->input("admin_id");
        if(empty($param['content']) || empty($param['data_type']) || empty($param['admin_id'])) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->shortcutWordService->addShortcutWord($param);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }

    /**
     * 编辑快捷语
     */
    public function editShortcutWord(Request $request)
    {
        $id = $request->input("id");
        $param['content'] = $request->input("content");
        $param['data_type'] = $request->input("data_type");
        $param['sort'] = (int) $request->input("sort");
        $param['admin_id'] = $request->input("admin_id");
        if(empty($id) || empty($param['content']) || empty($param['data_type']) || empty($param['admin_id'])) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->shortcutWordService->editShortcutWord($id, $param);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }

    /**
     * 删除快捷语
     */
    public function delShortcutWord(Request $request)
    {
        $id = $request->input("id");
        $param['admin_id'] = $request->input("admin_id");
        if(empty($id) || empty($param['admin_id'])) {
            Response::returnResult(Hint::PARAM_ERROR);
        }

        $data = $this->shortcutWordService->delShortcutWord($id, $param);
        if($data['code'] != Hint::SUCCESS) {
            Response::returnResult($data['code'], $data['data'], $data['msg']);
        }

        Response::returnResult(Hint::SUCCESS, $data['data']);
    }

}